package com.element5th.shop.servlet.good;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.element5th.shop.comm.DaoFactory;
import com.element5th.shop.dao.good.IAdminGoodDao;
import com.element5th.shop.dto.BaseDto;

/**
 * Servlet implementation class AdminAddBigClass
 */
@WebServlet("/page/admin/page/add_class")
public class AdminAddClass extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminAddClass() {
        super();
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		String msg = null;
		String path = "/page/admin/page/add_goodclass.jsp";
		
		int bigClassId = Integer.parseInt(request.getParameter("bigClassList"));
		String className = request.getParameter("className");
		
		BaseDto dto = new BaseDto();
		dto.getGoodClass().setBigclassId(bigClassId);
		dto.getGoodClass().setClassName(className);
		
		IAdminGoodDao dao = DaoFactory.getAdminGoodDao();
		if(dao.addClass(dto)) {
			msg = "添加成功";
		} else {
			msg = "添加失败";
		}
		request.setAttribute("msg", msg);
		
		this.getServletContext().getRequestDispatcher(path).forward(request, response);
	}

}
